import jdk.nashorn.internal.parser.Scanner;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Test {
    public static String func3(){
        StringBuilder sb = new StringBuilder("abcd");
        return sb.toString();
    }

    public static String func4(){
        StringBuffer sb = new StringBuffer("abcd");
        return sb.toString();
    }

    // 要想把字符串转换成StringBuilder类型/StringBuffer类型，必须调用对应的构造方法
    public static StringBuilder func1(){
        String str = "abcdef";
        return new StringBuilder(str);
    }

    public static StringBuffer func2(){
        String str = "abcdef";
        return new StringBuffer(str);
    }

    public static void main(String[] args) {

    }

    public static void main43(String[] args) {
        StringBuilder sb1 = new StringBuilder("abcdef");
        sb1.reverse();
        System.out.println(sb1);
        StringBuffer sb2 = new StringBuffer("123456");
        sb2.reverse();
        System.out.println(sb2);
    }

    public static void main42(String[] args) {
        StringBuilder sb = new StringBuilder();
        sb.append("abcdef");
        for (int i = 0; i < 10; i++) {
            sb.append(i);
        }
        System.out.println(sb);
    }

    public static void main41(String[] args) {
        //String str = "abcdef";
        StringBuilder sb = new StringBuilder();
        sb.append("abcdef");
        //str+="123";
        sb.append("123");
        //System.out.println(str);
        System.out.println(sb);
    }

    public static void main40(String[] args) {
        StringBuilder sb = new StringBuilder();
        sb.append("abcdef").append("12345");
        System.out.println(sb);
    }

    public static void main39(String[] args) {
        StringBuilder sb = new StringBuilder("abcdef");
        System.out.println(sb.toString());
    }

    public static void main38(String[] args) {
        String str = "";
        System.out.println(str.length());
        System.out.println(str.isEmpty());
        System.out.println("=======");
        String str1 =  "     ";
        System.out.println(str1.length());
        System.out.println(str1.isEmpty());
    }

    public static void main37(String[] args) {
        String str1 = "ab";
        String[] str2 = new String[5];
        System.out.println(str1.length());
        System.out.println(str2.length);
    }

    public static void main36(String[] args) {
        String str1 = "ab";
        String str2 = "cd";
        String str3 = str1.concat(str2);
        System.out.println(str3);
    }

    public static void main35(String[] args) {
        String str = "abcDEF123道";
        String str1 = str.toLowerCase();
        System.out.println(str1);
    }

    public static void main34(String[] args) {
        String str = "abcDEF123道";
        String str1 = str.toUpperCase();
        System.out.println(str1);
    }

    public static void main33(String[] args) {
        String str = "   a    d      ";
        String str1 = str.trim();
        System.out.print(str1);
        System.out.print("====");
    }

    public static void main32(String[] args) {
        String str = "abcd";
        String sub = str.substring(0,2);
        System.out.println(sub);
    }


    public static void main31(String[] args) {
        String str = "abcd";
        String sub = str.substring(0);// 提取子串
        System.out.println(sub == str);
    }

    public static void main30(String[] args) {
        String str = "java30 12&21#hello";
        String[] strings = str.split(" |&|#");
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main29(String[] args) {
            String str = "192\\168\\1\\1";
            String[] strings =str.split("\\\\",2);
            for (String s:strings) {
                System.out.println(s);
        }
    }

    public static void main28(String[] args) {
        String str = "192.168.1.1";
        String[] strings =str.split("\\.",2);
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main27(String[] args) {
        String str1 = "192.168.1.1";
        String[] strings = str1.split("\\.");
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main26(String[] args) {
// 假设我们想要取到 name = zhangsan  和 age=19，但是中间隔着一个&符号，其中作用就是分割。
        // 方便我们拿到数据，因为我们可以使用 split 方法 去处理分割，拿到我们想要的数据
        String str = "name=zhangsan&age=19";
        String[] strings = str.split("&");
        for (String s:strings) {
            String[] ss = s.split("=");
            for (String sss:ss){
                System.out.println(sss);
            }
        }
    }

    public static void main25(String[] args) {
// 假设我们想要取到 name = zhangsan  和 age=19，但是中间隔着一个&符号，其中作用就是分割。
        // 方便我们拿到数据，因为我们可以使用 split 方法 去处理分割，拿到我们想要的数据
        String str = "name=zhangsan&age=19";
        String[] strings = str.split("&");
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main24(String[] args) {
        String str = "abababcabababcd";
        String str1 = str.replaceFirst("ab","gg");
        System.out.println(str1);
    }

    public static void main23(String[] args) {
        String str = "abababcabababcd";
        String str1 = str.replace("ab","gg");
        System.out.println(str1);
    }

    public static void main22(String[] args) {
        String str = "abababcabababcd";
        String str1 = str.replace('a','g');
        System.out.println(str1);
    }

    public static void main21(String[] args) {
        String str = "abababcabababcd";
        System.out.println(str.endsWith("d"));
        System.out.println(str.endsWith("b"));
    }

    public static void main20(String[] args) {
        String str = "abababcabababcd";
        System.out.println(str.startsWith("c",6));
        System.out.println(str.startsWith("b",6));
    }

    public static void main19(String[] args) {
        String str = "abababcabababcd";
        System.out.println(str.startsWith("a"));
        System.out.println(str.startsWith("abab"));
        System.out.println(str.startsWith("abc"));
    }

    public static void main18(String[] args) {
        String str = "abababcabababcd";
        String tmp = "abc" ;
        int lastIndex = str.lastIndexOf(tmp,10);
        System.out.println(lastIndex);
    }


    public static void main17(String[] args) {
        String str = "abababcabababcd";
        String tmp = "abc" ;
        int lastIndex = str.lastIndexOf(tmp);
        System.out.println(lastIndex);
    }


    public static void main16(String[] args) {
        String str = "abababcabababcd";
        String tmp = "abcde" ;
        int index = str.indexOf(tmp,5);
        System.out.println(index);
    }

    public static void main15(String[] args) {
        String str = "abababcabababcd";
        String tmp = "abcde";// 字符串tmp  的 abc，字符串str 是有的
        int i = str.indexOf(tmp);// indexOf 会帮我们找到在 str中，从前往后找第一次出现 abc 的位置，返回 a的下标/偏移量
        // 如果没找到，就返回-1
        System.out.println(i);
    }
    public static void main14(String[] args) {
        String str = "abababcabababcd";
        String tmp = "abc";// 字符串tmp  的 abc，字符串str 是有的
        boolean b = str.contains(tmp);// contains 会帮我们找到在 str中，从前往后找第一次出现的 abc
        // 找到了就返回 true，没找到就false。
        System.out.println(b);
    }
    public static void main13(String[] args) {
        String str1 = "abc";
        String str2 = "Abc";
        String str3 = "abcd";
        System.out.println(str1.compareTo(str3));
        System.out.println(str2.compareTo(str2));
    }

    public static void main12(String[] args) {
        String str = "abc";
        String str1 = "Abc";
        String str2 = "abc";
        String str3 = "author";
        System.out.println(str.equalsIgnoreCase(str1));
        System.out.println(str.equalsIgnoreCase(str2));
        System.out.println(str.equalsIgnoreCase(str3));
    }

    public static void main11(String[] args) {
        String str1 = "abcde";
        String str2 = "abcde";
        System.out.println(str1.equals(str2));
    }

    public static void main10(String[] args) throws UnsupportedEncodingException {
        String str = "abcd";
        byte[] bytes = str.getBytes("utf-8");
        System.out.println(Arrays.toString(bytes));

        System.out.println("=========================");

        byte[] bytes2 = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes2));

    }

    public static void main9(String[] args) {
        String str = "abcd";
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
    }



    public static void main7(String[] args) {
        byte[] bytes = {97,98,99,100};
        String str = new String(bytes,1,3);
        System.out.println(str);
    }

    public static void main8(String[] args) {
        byte[] bytes = {97,98,99,100};
        String str = new String(bytes,3);
    }

    public static void main6(String[] args) {
        byte[] bytes = {97,98,99,100};
        String str = new String(bytes);
        System.out.println(str);
    }


    public  static boolean isNumberChar(String s){
        for (int i = 0; i < s.length(); i++) {
             char c =s.charAt(i);
             boolean flg =  Character.isDigit(c);
             if(flg == false){
                 return flg;
             }
        }
        return true;
    }

    public static void main5(String[] args) {
        String str = "1234";
        System.out.println(isNumberChar(str));
    }

    public static void main4(String[] args) {
        String str = "hello";
        // 将 str指向的字符串对象，转换成 字符数组对象，并将其地址返回。
        char[] chars = str.toCharArray();
        System.out.println(Arrays.toString(chars));
    }

    public static void main3(String[] args) {
        String str = "hello";
        char ch = str.charAt(4);
        System.out.println(ch);
    }

    public static void main2(String[] args) {
        char[] val = {'a','b','c','d','e'};
        String str = new String(val,1,4);
        System.out.println(str);
    }

    public static void main1(String[] args) {
        char[] val = {'a','b','c','d','e'};
        String str = new String(val);
        System.out.println(str);
    }
}
